home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
DesktopDoubler
/
Nub
/
Display.c
< prev
next >
Wrap
Text File
|
1999-06-26
|
7KB
|
336 lines
#define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
#define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
#include "DebugUtils.h"
#include <LowMem.h>
#include "ContextUtils.h"
#include "Display.h"
#include "DisplayManager.h"
#include "ProcInfo.h"
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
#endif
typedef struct NewSysWindowPB
{
Rect *bounds;
StringPtr title;
Boolean visible;
short procID;
WindowPtr behind;
Boolean goAwayFlag;
SInt32 refcon;
SysWindowHandlerUPP handler;
RgnHandle rgn;
} NewSysWindowPB;
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
static pascal OSErr SysWindowHandler(WindowPtr window,EventRecord *event,SInt16 part,Boolean *handled);
static pascal OSErr DragTrackingHandler(DragTrackingMessage message,WindowPtr window,void *refcon,DragReference drag);
#ifdef __cplusplus
}
#endif
static short gNewSysWindowGlue[] = { 0x4E56, 0x0000, 0x2F0A, 0x246E, 0x0008, 0x594F,
0x2F12, 0x2F2A, 0x0004, 0x1F2A, 0x0008, 0x3F2A,
0x000A, 0x2F2A, 0x000C, 0x1F2A, 0x0010, 0x2F2A,
0x0012, 0x2F2A, 0x0016, 0x2F2A, 0x001A, 0x3F3C,
0x005A, 0xA88F, 0x205F, 0x2008, 0x245F, 0x4E5E,
0x4E75 };
#if GENERATINGPOWERPC
static RoutineDescriptor gSysWindowHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppSysWindowHandlerProcInfo,SysWindowHandler);
static SysWindowHandlerUPP gSysWindowHandlerUPP = (RoutineDescriptor*)&gSysWindowHandlerRD;
static RoutineDescriptor gDragTrackingHandlerRD = BUILD_ROUTINE_DESCRIPTOR(uppDragTrackingHandlerProcInfo,DragTrackingHandler);
static DragTrackingHandlerUPP gDragTrackingHandlerUPP = (RoutineDescriptor*)&gDragTrackingHandlerRD;
#else
static SysWindowHandlerUPP gSysWindowHandlerUPP = SysWindowHandler;
static DragTrackingHandlerUPP gDragTrackingHandlerUPP = DragTrackingHandler;
#endif
extern DisplayManager *gDMan;
Display::Display(UInt32 index)
{
fIndex = index;
fGDev = NULL;
fDisplayID = NULL;
fCloneDisplay = false;
fCoverWindow = NULL;
fMBarWindow = NULL;
}
Display::~Display(void)
{
}
OSStatus Display::Create(GDHandle gdevToClone,DisplayIDType displayID,Boolean clone)
{
RGBColor black = { 0, 0, 0 };
GrafPtr port;
Rect bounds;
OSStatus err;
if (clone)
fGDev = gdevToClone;
else
{
err = DMNewDisplay(&fGDev,gdevToClone[0]->gdRefNum,gdevToClone[0]->gdMode,0,displayID,0,NULL);
if (err != noErr)
{
dprintf(kDConPrefix "DMNewDisplay failed: %ld",err);
return err;
}
}
DMGetDisplayIDByGDevice(fGDev,&fDisplayID,false);
fCloneDisplay = clone;
bounds = fGDev[0]->gdRect;
bounds.top += LMGetMBarHeight();
InsetRect(&bounds,1,1);
fCoverWindow = NewSysWindow(&bounds,"\p",false,plainDBox,(WindowPtr)(-1L),false,this,NULL);
dAssert(fCoverWindow != NULL);
if (fCoverWindow == NULL)
return -1;
if (InstallTrackingHandler != NULL)
{
err = InstallTrackingHandler(gDragTrackingHandlerUPP,fCoverWindow,this);
if (err != noErr)
dprintf(kDConPrefix "InstallTrackingHandler failed: %ld\n",err);
}
GetPort(&port);
SetPort(fCoverWindow);
RGBBackColor(&black);
SetPort(port);
ShowWindow(fCoverWindow);
bounds = fGDev[0]->gdRect;
bounds.bottom = bounds.top + LMGetMBarHeight();
InsetRect(&bounds,1,1);
fMBarWindow = NewSysWindow(&bounds,"\p",true,plainDBox,(WindowPtr)(-1L),false,this,NULL);
dAssert(fMBarWindow != NULL);
if (fMBarWindow == NULL)
return -1;
dprintf(kDConPrefix "Display::Create: index = %ld, displayID = $%08lX\n",fIndex,displayID);
return noErr;
}
void Display::Destroy(void)
{
OSStatus err;
dprintf(kDConPrefix "Display::Destroy: index = %ld, displayID = $%08lX\n",fIndex,fDisplayID);
if (fMBarWindow != NULL)
{
DisposeSysWindow(fMBarWindow);
fMBarWindow = NULL;
}
if (fCoverWindow != NULL)
{
if (RemoveTrackingHandler != NULL)
RemoveTrackingHandler(gDragTrackingHandlerUPP,fCoverWindow);
DisposeSysWindow(fCoverWindow);
fCoverWindow = NULL;
}
if ((fGDev != NULL) && !fCloneDisplay)
{
err = DMRemoveDisplay(fGDev,NULL);
if (err != noErr)
dprintf(kDConPrefix "DMRemoveDisplay failed: %ld",err);
fGDev = NULL;
}
}
void Display::MoveTo(SInt16 x,SInt16 y)
{
if (fCoverWindow != NULL)
MoveWindow(fCoverWindow,x,y + LMGetMBarHeight(),false);
if (fMBarWindow != NULL)
MoveWindow(fMBarWindow,x,y,false);
}
Boolean Display::Contains(Point where)
{
return PtInRect(where,&fGDev[0]->gdRect);
}
void Display::ShowHide(Boolean show)
{
::ShowHide(fCoverWindow,show);
}
Boolean Display::EventHandler(WindowPtr window,EventRecord *event,SInt16 part)
{
Boolean handled = true;
switch(event->what)
{
case mouseDown:
if (window == fMBarWindow)
{
gDMan->MBarClick(this,event->where);
break;
}
goto unhandled;
break;
case updateEvt:
BeginUpdate(window);
EndUpdate(window);
break;
case osEvt:
if (((event->message >> 24) & 0xFF) == mouseMovedMessage)
break;
goto unhandled;
break;
unhandled:
default:
dprintf(kDConPrefix "EventHandler: window = $%08lX, what = %ld, msg = $%08lX, where = %ld,%ld, part = %ld\n",
window,event->what,event->message,event->where.h,event->where.v,part);
handled = false;
break;
}
return handled;
}
#if 0
#pragma mark -
#endif
WindowPtr NewSysWindow(Rect *bounds,StringPtr title,Boolean visible,SInt16 procID,WindowPtr behind,
Boolean goAwayFlag,SysWinHandler *handler,RgnHandle rgn)
{
NewSysWindowPB pb;
SInt32 result;
pb.bounds = (Rect*)bounds;
pb.title = (StringPtr)title;
pb.visible = visible;
pb.procID = procID;
pb.behind = behind;
pb.goAwayFlag = goAwayFlag;
pb.refcon = (SInt32)handler;
pb.handler = gSysWindowHandlerUPP;
pb.rgn = rgn;
result = CallUniversalProc((UniversalProcPtr)gNewSysWindowGlue,
kCStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NewSysWindowPB*))),
&pb);
return *(((WindowPtr*)&result) + RESULT_OFFSET(WindowPtr));
}
OSErr DisposeSysWindow(WindowPtr window)
{
SInt32 result;
result = CallUniversalProc(NGetTrapAddress(0xA88F,ToolTrap),
kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(UInt16))),
window,
0x005B);
return *(((OSErr*)&result) + RESULT_OFFSET(OSErr));
}
pascal OSErr SysWindowHandler(WindowPtr window,EventRecord *event,SInt16 part,Boolean *handled)
{
GlobalContext globals;
THzContext zone(SystemZone());
*handled = ((SysWinHandler*)((WindowPeek)window)->refCon)->EventHandler(window,event,part);
return noErr;
}
pascal OSErr DragTrackingHandler(DragTrackingMessage message,WindowPtr window,void *refcon,DragReference drag)
{
gDMan->Swap((Display*)refcon);
return -1;
}